package zero.slr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import zero.util.ListUtils;

/**
 * 项目规范集
 * 
 * @author Zero
 *
 */
public class ItemSet {
    private Integer              number = null;
    private List<Item>           items  = new ArrayList<>();
    private Map<String, ItemSet> goMap  = new HashMap<>();

    public ItemSet() {

    }

    public ItemSet(Integer number, List<Item> items) {
        this.number = number;
        this.items  = items;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ItemSet)) {
            return false;
        }

        ItemSet o = (ItemSet) obj;

        return ListUtils.isEqualList(items, o.getItems());
    }

    @Override
    public String toString() {
        StringBuffer buf = new StringBuffer();
        buf.append("[" + number + "]\n");
        for (Item item : items) {
            buf.append(item.toString());
            buf.append("\n");
        }

        return buf.toString();
    }

    public void merge(ItemSet itemSet) {
        addAll(itemSet.getItems());
    }

    public void addItem(Item item) {
        if (items.contains(item)) {
            return;
        }

        item.setNumber(items.size());
        items.add(item);
    }

    public void addAll(List<Item> items) {
        for (Item item : items) {
            item.setNumber(items.size());
            this.items.add(item);
        }
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }

    public Map<String, ItemSet> getGoMap() {
        return goMap;
    }

    public void setGoMap(Map<String, ItemSet> goMap) {
        this.goMap = goMap;
    }
}
